﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using hospital_registration_system.DAL;
using hospital_registration_system.Entity;

namespace hospital_registration_system.BLL
{
    public class IllnessService
    {
        IllnessDao dao = null;
        public IllnessService()
        {
            dao = new IllnessDao();
        }

        /// <summary>
        /// 查找所有的疾病
        /// </summary>
        /// <returns>返回所有科室的链表</returns>
        public List<Illness> selectAllIllness()
        {
            return dao.selectAll();
        }

        /// <summary>
        /// 删除指定id的疾病
        /// </summary>
        /// <param name="id">要删除疾病的id</param>
        /// <returns>操作是否成功</returns>
        public bool deleteIllnessById(int id)
        {
            if (id < 0) return false;//检查id属性是否符合要求
            return dao.delete(id);
        }

        /// <summary>
        /// 修改疾病信息
        /// </summary>
        /// <param name="departments">要修改的疾病信息</param>
        /// <returns></returns>
        public bool updateIllness(Illness illness)
        {
            if (illness == null || illness.Id < 0)
            {
                return false;
            }
            return dao.update(illness);
        }

        /// <summary>
        /// 插入新的疾病信息
        /// </summary>
        /// <param name="name">要插入的科室名</param>
        /// <returns></returns>
        public bool insertIllness(String name)
        {
            Illness illness = new Illness();
            illness.Illness_name = name;
            return dao.insert(illness);
        }

        /// <summary>
        /// 插入新的疾病与科室的关系
        /// </summary>
        /// <param name="illId"></param>
        /// <param name="depId"></param>
        /// <returns>执行是否成功</returns>
        public bool illnessAndDepartment(int illId,int depId)
        {
            Illness_departmentsDao dao1 = new Illness_departmentsDao();
            DepartmentsDao dao2 = new DepartmentsDao();
            if (dao.select(illId) == null) return false;
            if (dao2.selectById(depId) == null) return false;
            return dao1.insert(illId,depId);
        }

        protected Illness_departmentsDao dao2 = new Illness_departmentsDao();
        /// <summary>
        /// 根据疾病id查询疾病和科室的关系
        /// </summary>
        /// <param name="illnessId"></param>
        /// <returns></returns>
        public List<Illness_departments> selectIllDepByIllId(int illnessId)
        {
            return dao2.selectByIllnessId(illnessId);
        }

        /// <summary>
        /// 根据疾病与科室关系记录表id删除记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool deleteIll_depById(int id)
        {
            return dao2.delete(id);
        }
    }
}
